package com.hui.xiao.xiaohui.ui;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher;

import com.hui.xiao.xiaohui.R;

/**
 * Created by Administrator on 2016/5/21.
 */
public class TextSwitcherTest extends Activity {

    TextSwitcher switcher;
    String[] books = new String[]{
            "三国", "水浒", "西游", "红楼"
    };
    int curBook;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.text_switcher);
        switcher = (TextSwitcher) findViewById(R.id.text_switcher);
        switcher.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                TextView textView = new TextView(TextSwitcherTest.this);
                textView.setTextSize(40);
                textView.setTextColor(Color.MAGENTA);
                return textView;
            }
        });
        next(null);
    }

    public void next(View view) {
        switcher.setText(books[curBook++ % books.length]);
    }
}
